package com.yeung.exam;

import java.util.Scanner;

/*
3
1 3 6
 */
public class 奇安信_最短距离 {
    static int MIN = Integer.MAX_VALUE;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int[] input = new int[k];
        int ind = 0;
        while (ind < k)
            input[ind++] = sc.nextInt();
        //
        getSmall(input, k, 0);
        System.out.println(MIN);

    }

    static void getSmall(int[] input, int k, int index) {
        if (index == input.length) {
            int cha = getCha(input);
            if (cha < MIN) MIN = cha;
            return;
        }
        for (int i = index; i < input.length; i++) {
//            if (visited[i]) {
//                visited[i] = true;
            input[i] += k;
            getSmall(input.clone(), k, i + 1);
            input[i] -= (2 * k);
            getSmall(input.clone(), k, i + 1);

//            }
        }

    }

    static int getCha(int[] input) {
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        for (int num : input) {
            if (num > max) max = num;
            if (num < min) min = num;
        }
        return max - min;
    }
}
